var My2DSprite = Class.create({
    initialize: function(o, parentNode){
        // o = {imgSources}


        //Check neu imgSources là mảng thì gán luôn
        if(o.imgSources instanceof Array){
            //Mang chua duong dan den day danh sach cac hinh
            this.imgSources = o.imgSources;
        }
        else{
            var path = o.imgSources.pattern;
            var from = o.imgSources.from;
            var type = o.imgSources.fileType;
            var to = o.imgSources.to;
            this.imgSources = new Array();



            for(var  i = from;i <= to;i++){
                var t = 0,_i = i;
                while(_i > 0){
                    ++t;
                    _i =  Math.floor(_i / 10);
                };

                var subStr = path.slice(0, path.length - t);
                subStr = subStr + i + "." + type;
                this.imgSources.push(subStr);
            }
        }
        //Luu lai index hien tai trong day hinh
        this.currentImageIndex = 0;
        //Luu lai state hien tai cua object
        this.state = 0;
        //Bien IsSelected theo yeu cau
        this.isSelected = false;

        //Khoi tao dong thoi luu lai tag img dung de shot hinh len div can thiet
        this.imgTag = new Element('img', {'src': this.imgSources[this.currentImageIndex]});
        this.imgTag.setStyle({width: "100%", height: "100%"})

        if(parentNode !== undefined){
            $(parentNode).insert(this.imgTag);
        }
    },
    update: function(){
        //Ham update bay gio chi lam mot viec don gian la xoay vong array hinh moi khi duoc goi
        this.currentImageIndex = (this.currentImageIndex + 1) % this.imgSources.length;
        $(this.imgTag).writeAttribute('src', this.imgSources[this.currentImageIndex]);
    },
    draw: function(){}
});